#include "CFDPostOperatorsStreamLine.h"

#include "CFDPostDataManager/CFDPostDataManager.h"

#include "CFDPostGUIDialog/CFDPostStreamLineDialog.h".h"
#include "CFDPost/CFDPostOperatorsGUI/CFDPostOperModelTreeMouseEvent.h"
#include "CFDPost/CFDPostOperatorsInterface/CFDPostGraphEventOperator.h"

#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Interface/FITKInterfaceCFDPost/FITKCFDPost3DManager.h"
#include "FITK_Interface/FITKInterfaceCFDPost/FITKCFDPostData.h"

namespace OperModel
{
CFDPostOperatorsStreamLine::CFDPostOperatorsStreamLine()
{

}

bool CFDPostOperatorsStreamLine::execGUI()
{
    if(_senderName == "actionStreamlineCreate")
    {
        GUI::CFDPostStreamLineDialog* dialog = new GUI::CFDPostStreamLineDialog(
            DataManager::CFDPostDataManager::getInstance()->getTreeCurrentDataID(), this, true);
        dialog->show();
    }
    else if (_senderName == "actionStreamlineEdit")
    {
        int objID = -1;
        argValue(objID_String, objID);

        if (objID <= 0)
        {
            return false;
        }

        GUI::CFDPostStreamLineDialog* dialog = new GUI::CFDPostStreamLineDialog(objID, this, false);
        dialog->show();
    }

    return false;
}

bool CFDPostOperatorsStreamLine::execProfession()
{
    Interface::FITKCFDPost3DManager* manager = FITKAPP->getGlobalData()->getPostData<Interface::FITKCFDPostData>()->getPostDataManager();
    if (manager == nullptr)return false;
    EventOper::CFDPostGraphEventOperator* graphOper =FITKOPERREPO->getOperatorT<EventOper::CFDPostGraphEventOperator>("OperGraphPreprocess");
    if(graphOper==nullptr)return false;
    GUIOper::CFDPostOperModelTreeMouseEvent* treeOper =FITKOPERREPO->getOperatorT<GUIOper::CFDPostOperModelTreeMouseEvent>("CFDPostModelTreeEvent");
    if (treeOper == nullptr)return false;

    int objID = -1;
    argValue(objID_String, objID);
    Interface::FITKAbstractCFDPostData* data = manager->getDataByID(objID);
    if (data)
    {
        graphOper->updateSingle(objID);
    }

    treeOper->updateTree();
    return false;
}
}
